﻿using HCApp.UI.Windows;
using MainAppEntryPrismWpf.Views;
using Prism.Ioc;
using Prism.Modularity;
using System.Windows;
using LinnerToolkit.Core.Services;
using System;
using NLog;

namespace MainAppEntryPrismWpf
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : HCApplicationBase
    {
        protected override double DesignHeight => 1080;
        protected override double DesignWidth => 1920;

        public static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();

        System.Threading.Mutex mutex;
        public App()
        {
            NLog.LogManager.Setup().LoadConfiguration(builder => {
                builder.ForLogger().FilterMinLevel(NLog.LogLevel.Info).WriteToConsole();
                builder.ForLogger().FilterMinLevel(NLog.LogLevel.Debug).WriteToFile(fileName: "file.txt");
            });
            this.Startup += new StartupEventHandler(App_Startup);
        }
        void App_Startup(object sender, StartupEventArgs e)
        {
            bool ret;
            mutex = new System.Threading.Mutex(true, "MainAppEntryPrismWpf", out ret);

            if (!ret)
            {
                MessageBox.Show("已有一个程序实例运行");
                Environment.Exit(0);
            }

        }
        protected override async void OnInitialized()
        {
            base.OnInitialized();
            Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("NzAyOTc5QDMxMzkyZTM0MmUzMGR2ZWQ0N1g1REpVaG94NXdjWkdvZGtaSkJmU05tbmVSaVBuQU9qTFUvVFU9");


            //await BusinessController.Instance.CheckAndGetChannelInfoAsync(devCode: "HC-SM-REP223861242161");
            //var response = await UserController.Instance.VCodeLoginAsync("18017766021", "101303", "yjys");


            //var userInfo = UserController.Instance.CurrentUserInfo;

            //AudioManagerBase.Init(System.IO.Path.Combine(FileSystemConstants.CacheDirectory, "Audio"),
            //    true, "DE760042D3C570B4", "m1bfZDI4sKLjE+3StBtGEHvXSXqR0+a0jZf0uVnrKnQ=", true);

            await NavigationService.NavigateAsync("Page1");
        }
        protected override Window CreateShell()
        {
            return Container.Resolve<MainWindow>();
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            base.RegisterTypes(containerRegistry);
            containerRegistry.RegisterInstance(Container);
            containerRegistry.RegisterForNavigation<Page1>();
            containerRegistry.RegisterForNavigation<YGXXManagePage>();
            containerRegistry.RegisterForNavigation<GGManagePage>();
            containerRegistry.RegisterForNavigation<YGSignInPage>();
            containerRegistry.RegisterForNavigation<ChuKuManagePage>();
            containerRegistry.RegisterForNavigation<RuKuManagePage>();
            containerRegistry.RegisterForNavigation<HistoryReviewPage>();
            containerRegistry.RegisterForNavigation<DailyRepository>();
        }

        protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
        {
          

        }
    }
}
